<template>
  <Transition name="down">
    <div class="rbt-message" :style="style[type]">
      <!-- 上面绑定的是样式 -->
      <!-- 不同提示图标会变 -->
      <i class="iconfont" :class="[style[type].icon]"></i>
      <span class="text">{{ text }}</span>
    </div>
  </Transition>
</template>

<script setup lang="ts">
defineProps({
  text: {
    type: String,
    default: ''
  },
  type: {
    type: String,
    default: 'warn'
  }
})

// 定义一个对象 包含三种情况
const style = reactive<{ [key: string]: any }>({
  warn: {
    icon: 'icon-warning',
    color: '#e6a23c',
    backgroundColor: 'rgb(253, 246, 236)',
    borderColor: 'rgb(250, 236, 216)'
  },
  error: {
    icon: 'icon-shanchu',
    color: '#f56c6c',
    backgroundColor: 'rgb(254, 240, 240)',
    borderColor: 'rgb(253, 226, 226)'
  },
  success: {
    icon: 'icon-queren2',
    color: '#67c23a',
    backgroundColor: 'rgb(240, 249, 235)',
    borderColor: 'rgb(225, 243, 216)'
  }
})

const visible = ref(false)
onMounted(() => {
  visible.value = true
})
</script>

<style scoped lang="scss">
.rbt-message {
  width: 300px;
  height: 50px;
  position: fixed;
  z-index: 9999;
  left: 50%;
  margin-left: -150px;
  top: 25px;
  line-height: 50px;
  padding: 0 25px;
  border: 1px solid #e4e4e4;
  background: #f5f5f5;
  color: #999;
  border-radius: 4px;
  i {
    margin-right: 4px;
    vertical-align: middle;
  }
  .text {
    vertical-align: middle;
  }
}
.down-enter-active,
.down-leave-active {
  transition: opacity 0.5s ease;
}

.down-enter-from,
.down-leave-to {
  opacity: 0;
}
</style>
